﻿using System;
using System.Windows.Data;
using System.Windows;

namespace Eniux.Windows.Controls.Core.Converters
{
  public  class CornerRadiusConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null)
            {
                CornerRadius cr = new CornerRadius(0);
                CornerRadius _value = (CornerRadius)value;
                if(parameter!=null)
                {
                    string[] sArray=parameter.ToString().Split('_');
                    foreach(string str in sArray)
                    {
                        try
                        {
                            switch (str.ToString())
                            {
                                case "TopLeft": cr.TopLeft = _value.TopLeft; break;
                                case "TopRight": cr.TopRight = _value.TopRight; break;
                                case "BottomLeft": cr.BottomLeft = _value.BottomLeft; break;
                                case "BottomRight": cr.BottomRight = _value.BottomRight; break;
                            }

                        }
                        catch (Exception)
                        {
                            return value;
                        }
                    }
                }
                return cr;
            }
            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
